package com.example.mvvm.mvc.login;

import java.util.Random;

public class LoginModel {
    private api api;
    private Random random = new Random();
    public void doLogin(OnDoLoginStateChange callback, String username, String password) {
        callback.onLoginLoading();
        //开始调用登录api
        //api.login

        // 有结果，此操作为耗时操作
        int flag = random.nextInt(2);
        if(flag == 0){
            callback.onLoginSuccess();
        }else{
            callback.onLoginFailed();
        }
    }

    public int checkUsername(String username){
        //0表示该用户没注册，1表示该用户已注册
        int block = random.nextInt(2);
       return block;
    }

    interface OnDoLoginStateChange{
        void onLoginSuccess();
        void onLoginFailed();
        void onLoginLoading();
    }
}
